import pandas as pd
import numpy as np
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt

df = pd.read_csv('ans_ours_vgg.csv')

pre_labels = df['Category'].values

true_labels = df['Id'].str.split('_').str[0].astype(int).values

cm = confusion_matrix(true_labels, pre_labels)

plt.figure(figsize=(10, 8))
plt.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)
plt.title('Confusion Matrix')
plt.colorbar()
plt.xlabel('Predicted Label')
plt.ylabel('True Label')
plt.show()

print(cm)

accuracy = np.trace(cm) / np.sum(cm)
print(f"Accuracy: {accuracy:.4f}")